home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / DSMODS / CONVERT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  34.1 KB  |  1,089 lines

  1. /**************************************************************************/
  2. /*  FILE:  CONVERT.C        PROGRAM TITLE: DeskSET II Alpha Version   */
  3. /*  Date Created: 01/07/88                          */ 
  4. /*  Last Modified: 02/10/89                          */
  5. /*                                      */
  6. /*  Description: CONVERSION ROUTINES                      */
  7. /*  Routines:                                  */
  8. /*       o  hmutopix()          - Horizontal Machine Units to Pixels.     */
  9. /*    o  vmutopix()          - Vertical Machine Units to Pixels.       */
  10. /*    o  hpixtomu()          - Horizontal Pixels to Machine Units.     */
  11. /*    o  vpixtomu()          - Vertical Pixels to Machine Units.      */
  12. /*    o  scrntomu()          - Screen Pixels to Machine Units.      */
  13. /*    o  mutoscrn()          - Machine Units to Screen Pixels.      */
  14. /*    o  mutomem()           - Machine Units to Scanner Pixels      */
  15. /*    o  memtomu()           - Scanner to Machine Units          */
  16. /*    o  scale()             - Scale up/down MU to scrn/scrn to Mu     */
  17. /*    o  scale_xy()        - Scale up/down MU to scrn/scrn to Mu      */
  18. /*    o  itoa()              - Integer to ASCII conversion          */
  19. /*    o  reverse()           - Reverse text string - Used by itoa()    */
  20. /*    o  scale_me()         - scale up/down - used by scale()      */
  21. /*    o  mutopage()          - convert MU to Preview Page units        */
  22. /*    o  scale_iv()          - scaler for arrows,sliders etc.       */
  23. /*                  (ok, its really a muldiv...)          */
  24. /*      o  scale_v()        - another muldiv              */
  25. /*    o  mutolas()           - Machine Units to Laser Coordinates      */
  26. /*    o  pttomu()            - Point Size to Machine Units conversion  */
  27. /*    o  get_scale_num()    - Get current scale size (quick and dirty)*/
  28. /*                - based upon a muldiv for size to fit      */
  29. /*    o  scale_request()    - Get a scale number from table          */
  30. /*    o  scrn2mu()        - Scrn to Mu conversion - PADJCNT specific*/
  31. /*    o do_trans_scale()    - Translation and scaling for typed coords*/
  32. /*    o case12_scale()    - scale for opcodes 1 and 2 for typed "   */
  33. /*    o scale_prim_coord()                          */
  34. /*    o mutopt()                              */
  35. /**************************************************************************/
  36.  
  37.  
  38. /**************************************************************************/
  39. /* INCLUDE FILES                              */
  40. /**************************************************************************/
  41. #include "define.h"
  42. #include "deskset2.h"
  43. #include <obdefs.h>
  44. #include "gemdefs.h"
  45.  
  46. /**************************************************************************/
  47. /* DEFINES                                  */
  48. /**************************************************************************/
  49.  
  50.  
  51. /**************************************************************************/
  52. /* EXTERNALS                                  */
  53. /**************************************************************************/
  54. extern int sxres;                   /* screen x resolution */
  55. extern int syres;                   /* screen y resolution */
  56.  
  57. extern GRECT dpwork;                   /* window work area    */
  58. extern GRECT pwork;                   /* Preview window work */
  59.  
  60. extern int pagew,pageh;                   /* Current page width  */
  61.                            /* and height - pixels */
  62. extern int dummy;                   /* well, dummy         */
  63. extern GRECT page_area;                   /* blit area in preview*/
  64.                            /* area...          */
  65.                            /* in MU units...      */
  66. extern int pxyarray[];                   /* temp variable       */
  67. extern int pxy[];                   /* storage...      */
  68. extern int ptsarray[];                   /* interface array     */
  69.                            /* for conversions     */
  70. extern int alt_offset;
  71. extern int print_flag;
  72. extern int unit_type;
  73. extern double modf();
  74. extern int snap_to_grids;
  75. extern int deltax,deltay;
  76. extern unsigned long region_ptr;
  77. extern unsigned long gl_region_ptr;
  78. extern int count,wmode;
  79. extern long get_regart();
  80. extern int deferhj;
  81.  
  82. /**************************************************************************/
  83. /* GLOBAL VARIABLES                              */
  84. /**************************************************************************/
  85. int hpage_size;            /* Current Horizontal Page Size (MU)      */
  86. int vpage_size;            /* Current Vertical Page Size (MU)        */
  87.  
  88. int view_size;            /* Current Page Scale Size          */
  89. int curr_page;            /* Current Region Page              */
  90.  
  91. int tmpx,tmpy;            /* Several temp variables that are used   */
  92. int dumb;
  93.  
  94. int zdevice;            /* index for which device..          */
  95.                 /* Screen = 0, SCANNER = 1, Preview = 2   */
  96.                                 /* Laser = 3...                  */
  97. int axdpi[4]     = {80,80,80,300};
  98. int aydpi[4]     = {80,80,80,300};
  99. int half_xdpi[4] = {40,40,40,150};/* Screen, Scanner, Preview Laser 1/2xdpi*/
  100. int half_ydpi[4] = {40,40,40,150};/* Screen, Scanner, Preview Laser 1/2ydpi*/
  101.  
  102.  
  103. /**************************************************************************/
  104. /* Function:    hmutopix()                          */
  105. /* Description: Horizontal Machine Units to Horizontal Pixel Conversion   */
  106. /* INPUT : munits  - Machine Units (Horizontal)                    */
  107. /* OUTPUT: returns the number of horizontal pixels              */
  108. /*        Calculation is based upon: o horizontal dpi              */
  109. /*                      o 18 mu per point              */
  110. /*                      o 72 pt per inch              */
  111. /* GLOBALS:   axdpi[] - array containing dpi of destination device      */
  112. /*          zdevice- index into xdpi array                  */
  113. /**************************************************************************/
  114. int hmutopix(munits)
  115. int munits;
  116. {
  117.      long tmp;
  118.  
  119.      tmp = (long)axdpi[zdevice] * (long)munits;
  120.      munits = ((tmp % 1296L) > 648L);
  121.      tmp /= 1296L;
  122.      return((int)tmp + munits);
  123. }
  124.  
  125.  
  126.  
  127. /**************************************************************************/
  128. /* Function:    vmutopix()                          */
  129. /* Description: Vertical Machine Units to Vertical Pixel Conversion      */
  130. /* INPUT : munits - Machine Units (Vertical)                  */
  131. /* OUTPUT: returns the number of vertical pixels              */
  132. /*        Calculation is based upon: o vertical dpi              */
  133. /*                      o 16 mu per point              */
  134. /*                      o 72 pt per inch              */
  135. /* GLOBALS:   aydpi[] - array containing dpi of destination device      */
  136. /*          zdevice- index into ydpi array                  */
  137. /**************************************************************************/
  138. vmutopix(munits)
  139. int munits;
  140. {
  141.     long tmp;
  142.  
  143.     tmp = (long)aydpi[zdevice] * (long)munits;
  144.     munits = ((tmp % 1152L) > 576L);
  145.     tmp /= 1152L;
  146.     return((int)tmp + munits);
  147. }
  148.  
  149.  
  150.  
  151.  
  152.  
  153. /**************************************************************************/
  154. /* Function:     hpixtomu()                          */
  155. /* Description: Pixel to Horizontal Machine Unit Conversion          */
  156. /* INPUT : pixels - Horizontal Pixel units                  */
  157. /* OUTPUT: returns the number of Horizontal Machine Units          */
  158. /*        Calculation is based upon: o horizontal dpi              */
  159. /*                      o 18 mu per point              */
  160. /*                      o 72 pt per inch              */
  161. /* GLOBALS:   axdpi[] - array containing dpi of destination device      */
  162. /*          half_xdpi - array containin 1/2dpi of destination device    */
  163. /*              (used for defining rounding up/down... )      */
  164. /*          zdevice- index into xdpi array                  */
  165. /**************************************************************************/
  166. hpixtomu(pixels)
  167. int pixels;
  168. {
  169.    long tmp;
  170.  
  171.    tmp = (long)pixels * 1296L;
  172.    pixels = ((tmp % (long)axdpi[zdevice]) > (long)half_xdpi[zdevice]);
  173.    tmp /= (long)axdpi[zdevice];
  174.    return((int)tmp + pixels);
  175. }
  176.  
  177.  
  178.  
  179.  
  180. /**************************************************************************/
  181. /* Function:    vpixtomu()                          */
  182. /* Description: Vertical Pixel to Vertical Machine Unit Conversion      */
  183. /* INPUT : pixels - Vertical Pixel units                  */
  184. /* OUTPUT: returns the number of Vertical Machine Units              */
  185. /*        Calculation is based upon: o horizontal dpi              */
  186. /*                      o 16 mu per point              */
  187. /*                      o 72 pt per inch              */
  188. /* GLOBALS:   aydpi[] - array containing dpi of destination device      */
  189. /*          half_ydpi[] - array containing 1/2 dp of destination device */
  190. /*                (used for rounding up/down...)          */
  191. /*          zdevice- index into ydpi array                  */
  192. /**************************************************************************/
  193. vpixtomu(pixels)
  194. int pixels;
  195. {
  196.      long tmp;
  197.  
  198.      tmp = (long)pixels * 1152L;
  199.      pixels = ((tmp % (long)aydpi[zdevice]) > (long)half_ydpi[zdevice]);
  200.      tmp /= (long)aydpi[zdevice];
  201.      return((int)tmp + pixels);
  202. }
  203.  
  204.    
  205.  
  206.  
  207. /**************************************************************************/
  208. /* Function:    scrntomu()                          */
  209. /* Description: Converts Screen Coordinates to Machine Unit Coordinates   */
  210. /* INPUT:  ox,oy -  Screen Coordinates (Pixels)                  */
  211. /*         nx,ny -  Pointers returning Machine Unit Positions          */
  212. /*       flag  -  Flag  0 - Adjust for window offsets              */
  213. /*                  1 - Do Not Adjust for window offsets          */
  214. /*              Vertices need to be adjusted, lengths do not.   */
  215. /* OUTPUT: nx,ny contain new coordinate positions in machine units      */
  216. /* GLOBALS:  zdevice - defines index for destination device used to get   */
  217. /*               the devices dots per inch resolution          */
  218. /*         pwork   - GRECT structure of preview window work area.       */
  219. /*         pagew   - width of page in pixels on the screen          */
  220. /*         pageh   - height of page in pixels on the screen          */
  221. /*         hpage_size - horizontal page size in machine units          */
  222. /*         vpage_size - vertical page size in machine units          */
  223. /*         page_area  - GRECT defining blit rectangle in Preview buffer */
  224. /*            - page_area.g_x and page_area.g_y defines the     */
  225. /*              current offset of the scrolled preview window   */
  226. /*         view_size  - current view mode - PACTUAL etc...          */
  227. /**************************************************************************/
  228. scrntomu(ox,oy,nx,ny,flag)
  229. int ox,oy;                    /* Old x,y vertice      */
  230. int *nx,*ny;                    /* New adjusted vertice   */
  231. int flag;                    /* scale direction flag   */
  232. {
  233.          int tmpx;
  234.          int tmpy;
  235.      int hwidth;
  236.      
  237.  
  238.          tmpx    = ox;                /* save for later...      */
  239.          tmpy    = oy;
  240.      zdevice = SCREEN;            /* Device destination     */
  241.  
  242.          if(!flag)
  243.          {
  244.          tmpx -= dpwork.g_x;        /* adjust for work offset */
  245.          tmpy -= dpwork.g_y;        /* of the window...       */
  246.          }
  247.  
  248.  
  249.          if((view_size == PSIZE) ||        /* Want Size to Fit       */
  250.             (view_size == PADJCNT))
  251.          {
  252.         hwidth = ((view_size == PADJCNT) ? (hpage_size * 2) : (hpage_size));
  253.         *nx = scale_iv(tmpx,hwidth,pagew);  
  254.         *ny = scale_iv(tmpy,vpage_size,pageh);
  255.  
  256.         if(!flag && (view_size == PADJCNT) && (*nx > hpage_size))
  257.         {
  258.         alt_offset = TRUE;
  259.         *nx -= hpage_size;
  260.         }
  261.         else
  262.         alt_offset = FALSE;
  263.                             
  264.          }
  265.          else                    /* otherwise all others   */
  266.          {
  267.         alt_offset = FALSE;
  268.             scale_xy(&tmpx,&tmpy,1);
  269.             *nx = hpixtomu(tmpx);
  270.         *ny = vpixtomu(tmpy);
  271.  
  272.             if(!flag)                /* adjust for the scrolled*/
  273.         {                    /* offset off of the      */
  274.                 *nx += page_area.g_x;        /* window          */
  275.                 *ny += page_area.g_y;        /* be adjusted...         */
  276.             }                        
  277.          }
  278.  
  279. }
  280.  
  281.  
  282.  
  283.  
  284. /**************************************************************************/
  285. /* Function:    mutoscrn()                          */
  286. /* Description: Machine Units to Screen Coordinate Conversion          */
  287. /* INPUT:        ox,oy - Oldx Machine Unit Positions              */
  288. /*        nx,ny - New Screen Coordinates                  */
  289. /*        flag  - 0 - Add workx and worky for offsets.          */
  290. /*            1 - Don't Add workx and worky offsets.          */
  291. /*            Vertices need to be adjusted, lengths do not.     */
  292. /* OUTPUT: nx,ny contain new coordinate positions in pixel units      */
  293. /* GLOBALS:  zdevice - defines index for destination device used to get   */
  294. /*               the devices dots per inch resolution          */
  295. /*         pwork   - GRECT structure of preview window work area.       */
  296. /*         pagew   - width of page in pixels on the screen          */
  297. /*         pageh   - height of page in pixels on the screen          */
  298. /*         hpage_size - horizontal page size in machine units          */
  299. /*         vpage_size - vertical page size in machine units          */
  300. /*         page_area  - GRECT defining blit rectangle in Preview buffer */
  301. /*            - page_area.g_x and page_area.g_y defines the     */
  302. /*              current offset of the scrolled preview window   */
  303. /*         view_size  - current view mode - RCS numbers PACTUAL etc...  */
  304. /**************************************************************************/
  305. mutoscrn(ox,oy,nx,ny,flag)
  306. int ox,oy;
  307. int *nx,*ny;
  308. int flag;
  309. {
  310.        int txoffset,tyoffset;
  311.        int hwidth;
  312.  
  313.        tmpx    = ox;
  314.        tmpy    = oy;
  315.        zdevice = SCREEN;
  316.             
  317.        if((view_size == PSIZE) ||        /* Size to Fit...        */
  318.       (view_size == PADJCNT))
  319.        {
  320.         hwidth = ((view_size == PADJCNT)?(hpage_size * 2):(hpage_size));
  321.         *nx = scale_iv(pagew,tmpx,hwidth);
  322.         *ny = scale_iv(pageh,tmpy,vpage_size);
  323.        }
  324.        else                    /* All others...         */
  325.        {
  326.  
  327.            *nx = hmutopix(tmpx);        /* scale the data...     */
  328.        *ny = vmutopix(tmpy);
  329.            scale_xy(nx,ny,0);
  330.  
  331.            if(!flag)                /* and adjust for offset */
  332.            {                    /* of scrolling.  Note   */
  333.           txoffset = page_area.g_x;
  334.           tyoffset = page_area.g_y;
  335.  
  336. /*
  337.               scale_xy(&txoffset,&tyoffset,0);
  338.               *nx -= hmutopix(txoffset);    * that only vertices    *
  339.               *ny -= vmutopix(tyoffset);    * need to be adjusted   *
  340. */
  341.           
  342.               txoffset = hmutopix(txoffset);
  343.               tyoffset = vmutopix(tyoffset);
  344.               scale_xy(&txoffset,&tyoffset,0);
  345.               *nx -= txoffset;
  346.               *ny -= tyoffset;              
  347.            }                    /* only...         */
  348.        }
  349.  
  350.        if(!flag)                /* adjust for the offset */
  351.        {                    /* of the work window    */
  352.        *nx += dpwork.g_x;            /* Again, only vertices  */
  353.            *ny += dpwork.g_y;            /* need apply...         */
  354.        }
  355.  
  356. }
  357.  
  358.  
  359.  
  360.  
  361. /**************************************************************************/
  362. /* Function:    mutomem()                          */
  363. /* Description:    Converts Machine Units to Scanner Coordinates            */
  364. /* IN  : ox,oy  -  MU position to convert to the scan buffer.          */
  365. /* OUT : nx,ny  -  pixel positions in the scan buffer.              */
  366. /* NOTE: scan buffer is configured always for actual size...           */
  367. /*     with LEGAL size paper                          */
  368. /* GLOBALS:   zdevice - defines index for destination device used to get  */
  369. /*            the dots per inch resolution              */
  370. /**************************************************************************/
  371. mutomem(ox,oy,nx,ny)
  372. int ox,oy;
  373. int *nx,*ny;
  374. {
  375.     zdevice = SCANNER;
  376.     *nx = hmutopix(ox);
  377.     *ny = vmutopix(oy);
  378. }
  379.  
  380.  
  381.  
  382.  
  383. /**************************************************************************/
  384. /* Function:    memtomu()                          */
  385. /* Description:    Converts Scanner Coordinates to Machine Units              */
  386. /*                                      */
  387. /* IN : ox,oy   - scan buffer pixel positions to convert to MU          */
  388. /* OUT: nx,ny   - Converted machine units coordinates              */
  389. /* Note: Scan buffer is configured always for actual size...          */
  390. /*     with LEGAL size paper                          */
  391. /* GLOBALS:  zdevice - defines index for destination device used to get   */
  392. /*               the dots per inch resolution              */
  393. /**************************************************************************/
  394. memtomu(ox,oy,nx,ny)
  395. int ox,oy;
  396. int *nx,*ny;
  397. {
  398.      zdevice = SCANNER;
  399.      *nx = hpixtomu(ox);
  400.      *ny = vpixtomu(oy);
  401.      if((curr_page % 2) && (view_size == PADJCNT) && !print_flag)
  402.             *nx += hpage_size;
  403. }
  404.  
  405.  
  406.  
  407.  
  408. /**************************************************************************/
  409. /*  Function:     scale()                          */
  410. /*  Description: Scale routine to convert a data pair from:          */
  411. /*         o A percentage to absolute 100% size ( % to MU)      */
  412. /*         o Absolute 100% to any percentage size (MU to %)      */
  413. /*  IN:    tx,ty       - vertice                      */
  414. /*         txoff,tyoff - x and y offset of scrolling.              */
  415. /*       flag        - direction of scaling - up or down.          */
  416. /*             0 - mu to percentage   1 - percentage to mu      */
  417. /*  OUT:   tx,ty       - adjusted vertice                  */
  418. /*         txoff,tyoff - adjusted x and y offset (compensates scrolling      */
  419. /* I believe that this routine is called by only one function.  The others*/
  420. /* use scale_xy() for a better usage of the stack.              */
  421. /**************************************************************************/
  422. scale(tx,ty,txoff,tyoff,flag)
  423. int *tx,*ty;
  424. int *txoff,*tyoff;
  425. int flag;                    /* 0 - mu to percentage   */
  426. {                        /* 1 - percentage to MU   */
  427.       int scaler;
  428.  
  429.       scaler = scale_request(view_size);    /* get a scale factor      */
  430.       *tx    = scale_me(*tx,scaler,flag);    /* scale them...       */
  431.       *ty    = scale_me(*ty,scaler,flag);    
  432.       *txoff = scale_me(*txoff,scaler,flag);    
  433.       *tyoff = scale_me(*tyoff,scaler,flag);
  434. }
  435.  
  436.  
  437.  
  438.  
  439.  
  440. /**************************************************************************/
  441. /* Function: scale_xy()                              */
  442. /* Description:    same as scale, but used for those who only need to handle */
  443. /*        vertices and nothing else.                  */
  444. /* IN:  tx,ty - pointers to the vertice                      */
  445. /*    flag  - direction of conversion                      */
  446. /*        o  0 = 100% to any percentage (MU to %)              */
  447. /*        o  1 = percentage to 100%     (% to MU)              */
  448. /* OUT: tx,ty are pointers to new numbers.                  */
  449. /**************************************************************************/
  450. scale_xy(tx,ty,flag)
  451. int *tx,*ty;
  452. int flag;                    /* 0 - mu to percentage   */
  453. {                        /* 1 - percentage to MU   */
  454.       int scaler;
  455.  
  456.       scaler = scale_request(view_size);    /* get scale factor       */
  457.       *tx    = scale_me(*tx,scaler,flag);    /* and scale them...       */
  458.       *ty    = scale_me(*ty,scaler,flag);    
  459. }
  460.  
  461.  
  462.  
  463.  
  464. /**************************************************************************/
  465. /*  Function:     itoa()                          */
  466. /*  Description:  Integer to ASCII conversion                  */
  467. /**************************************************************************/
  468. itoa(n,s)
  469. int n;
  470. register char s[];
  471. {
  472.     register int i;
  473.     int sign;
  474.     if((sign = n) < 0)
  475.        n = -n;
  476.     i = 0;
  477.     do
  478.     {
  479.     s[i++] = n % 10 + '0';
  480.     }while(( n /= 10) > 0);
  481.  
  482.     if(sign < 0)
  483.        s[i++] = '-';
  484.     s[i] = '\0';
  485.     reverse(s);
  486. }
  487.  
  488.  
  489.  
  490.  
  491. /**************************************************************************/
  492. /*  Function:    reverse()                          */
  493. /*  Description: reverses a text string. Used by itoa()              */
  494. /**************************************************************************/
  495. reverse(s)
  496. register char s[];
  497. {
  498.      int c;
  499.      register int i,j;
  500.  
  501.      for(i=0,j=strlen(s) - 1; i<j; i++,j--)
  502.      {
  503.           c    = s[i];
  504.           s[i] = s[j];
  505.       s[j] = c;
  506.      }
  507. }
  508.  
  509.  
  510.  
  511.  
  512. /**************************************************************************/
  513. /*  Function:    scale_me()                          */
  514. /*  Description: Performs actual scaling of data.              */
  515. /*         called by scale()                      */
  516. /*  IN:      num    - number to scale                      */
  517. /*         scaler - scale factor                      */
  518. /*         flag   - scale from    0 - mu to percentage          */
  519. /*                          1 - percentage to mu          */
  520. /*  OUT:     returns in D0 the newly scaled number              */
  521. /**************************************************************************/
  522. scale_me(num,scaler,flag)
  523. int  num;
  524. int  scaler;
  525. int  flag;
  526. {
  527.       long  tmp;
  528.       int  extra;
  529.       long  half;      
  530.  
  531.       if(!flag)            /*scale from full size to percentage  */
  532.       {
  533.            tmp = (long)num * (long)scaler;
  534.            extra = ((tmp % 100L) > 50L);
  535.        tmp /= 100L;
  536.        return((int)tmp + extra);
  537.       }
  538.       else            /* scale from percentage to full size */
  539.       {
  540.            half = (long)scaler / 2L;
  541.        tmp = (long)num * 100L;
  542.        extra = ((tmp % (long)scaler) > half);
  543.            tmp /= (long)scaler;
  544.            return((int)tmp + extra);
  545.       }     
  546.  
  547. }
  548.  
  549.  
  550.  
  551.  
  552. /**************************************************************************/
  553. /*  Function:    mutopage()                          */
  554. /*  Description: Scale from MU to Preview Page Memory Driver          */
  555. /*  IN:      ox,oy  - MU units to convert to pixels              */
  556. /*  OUT:     nx,ny  - Returns Pixel units in Preview Page mode          */
  557. /*  GLOBALS: zdevice - defines index for destination device used to get   */
  558. /*               the devices dots per inch resolution          */
  559. /*         pagew   - width of page in pixels on the screen          */
  560. /*         pageh   - height of page in pixels on the screen          */
  561. /*         hpage_size - horizontal page size in machine units          */
  562. /*         vpage_size - vertical page size in machine units          */
  563. /*         view_size  - current view mode - RCS numbers PACTUAL etc...  */
  564. /**************************************************************************/
  565. mutopage(ox,oy,nx,ny,flag)
  566. int ox,oy;
  567. int *nx,*ny;
  568. int flag;
  569. {
  570.        int hwidth;
  571.  
  572.        tmpx = ox;
  573.        tmpy = oy;
  574.  
  575.        zdevice = PREVIEW;
  576.  
  577.        if((view_size == PSIZE) ||        /* Handle Size to Fit     */
  578.       (view_size == PADJCNT))
  579.        {
  580.         hwidth = ((view_size == PADJCNT)?(hpage_size*2):(hpage_size));
  581.         *nx = scale_iv(pagew,tmpx,hwidth);
  582.         *ny = scale_iv(pageh,tmpy,vpage_size);
  583.         if(!flag && (curr_page % 2) && (view_size == PADJCNT))
  584.             *nx += pagew/2;
  585.        }
  586.        else                    /* And all others...       */
  587.        {                    /* Scale down appropriately*/
  588.            *nx = hmutopix(tmpx);
  589.        *ny = vmutopix(tmpy);
  590.            scale_xy(nx,ny,0);
  591.        }
  592. }
  593.  
  594.  
  595.  
  596.  
  597. /**************************************************************************/
  598. /*  Function:    scale_iv()                          */
  599. /*  Description: A muldiv based on input paramters of INT, LONG, LONG     */
  600. /*  IN:      visible  - amount of document visible              */
  601. /*         factor   - new percentage to modify by...              */
  602. /*         total    - total size of document                  */
  603. /*  OUT:     Returns in D0 an adjusted size factor              */
  604. /**************************************************************************/
  605. scale_iv(visible,factor,total)
  606. int visible;
  607. int factor;
  608. int total;
  609. {
  610.       long tmp;
  611.       int munits;
  612.       long half;
  613.  
  614.       half = ((long)total / 2L);
  615.  
  616.       tmp = (long)visible * (long)factor;
  617.       munits = ((tmp % (long)total) > half);
  618.       tmp /= (long)total;
  619.       return((int)tmp + munits);
  620. }
  621.  
  622.  
  623.  
  624.  
  625.  
  626. /**************************************************************************/
  627. /* Function:     scale_v()                          */
  628. /* Description:  Another MULDIV based on INT, INT, INT              */
  629. /*  IN:      visible  - amount of document visible              */
  630. /*         factor   - new percentage to modify by...              */
  631. /*         total    - total size of document                  */
  632. /*  OUT:     Returns in D0 an adjusted size factor              */
  633. /**************************************************************************/
  634. scale_v(visible,factor,total)
  635. int visible;
  636. int factor;
  637. int total;
  638. {
  639.       long tmp;
  640.       int  munits;
  641.       long half;
  642.  
  643.       half = ((long)total / 2L);
  644.  
  645.       tmp = (long)visible * (long)factor;
  646.       munits = ((tmp % (long)total) > half);
  647.       tmp /= (long)total;
  648.       return((int)tmp + munits);
  649. }
  650.  
  651.  
  652.  
  653.  
  654. /**************************************************************************/
  655. /* Function:    mutolas()                          */
  656. /* Description:    Converts Machine Units to Laser Driver Coordinates        */
  657. /* IN: ox,oy  - MU position to convert to the laser buffer.          */
  658. /* OUT: nx,ny - pixel positions in the laser buffer.              */
  659. /* NOTE: Laser buffer is configured always for actual size...           */
  660. /* GLOBAL:  zdevice - used to define device mode for conversion routines  */
  661. /**************************************************************************/
  662. mutolas(ox,oy,nx,ny)
  663. int ox,oy;
  664. int *nx,*ny;
  665. {
  666.     zdevice = LASER;
  667.     *nx = hmutopix(ox);
  668.     *ny = vmutopix(oy);
  669. }
  670.  
  671.  
  672.  
  673. /**************************************************************************/
  674. /* Function:    pttomu()                          */
  675. /* Description:    Point Size Text to Vertical Machine Units.          */
  676. /* IN:   ptsize  - Point Size of Text                      */
  677. /* OUT:  Returns vertical machine units.                  */
  678. /**************************************************************************/
  679. pttomu(ptsize)
  680. {
  681.     return(16*ptsize);
  682. }
  683.  
  684.  
  685.  
  686.  
  687. /**************************************************************************/
  688. /* Function:    get_scale_num()                          */
  689. /* Description: get a scale for the current size to pass to do_text       */
  690. /* IN: size - current viewing mode in RCS units - ie: PACTUAL          */
  691. /* OUT: returns a scale # from 1 to 200                      */
  692. /* GLOBAL:      vpage_size - vertical page size in machine units      */
  693. /*              pwork.g_h  - height of preview work window          */
  694. /**************************************************************************/
  695. get_scale_num(size)
  696. int size;
  697. {
  698.    int hwidth;
  699.    int column;
  700.    int pixw,pixh;
  701.  
  702.    if( (view_size == PSIZE) || (view_size == PADJCNT))
  703.    {
  704.       pixw = hmutopix(hpage_size);
  705.       pixh = vmutopix(vpage_size);
  706.  
  707.       hwidth = ((view_size == PADJCNT) ? (pixw * 2) : (pixw));
  708.       column = ((view_size == PADJCNT) ? (dpwork.g_w/2) : (dpwork.g_w));
  709.       if(dpwork.g_w <= scale_iv(dpwork.g_h,hwidth,pixh))
  710.          return(scale_iv(column,100,pixw));
  711.       else
  712.          return(scale_iv(dpwork.g_h,100,pixh));
  713.    }
  714.    else
  715.      return(scale_request(size));
  716. }
  717.  
  718.  
  719.  
  720.  
  721. /**************************************************************************/
  722. /* Function:  scale_request()                          */
  723. /* Description: Gets a scale factor from a table between 1 to 200      */
  724. /* IN: size - view mode in RCS units ie: PACTUAL              */
  725. /* OUT: returns scale factor between 1 to 200                  */
  726. /* GLOBAL: scale_set - current setting of user defined mode.          */
  727. /**************************************************************************/
  728. scale_request(size)
  729. int size;
  730. {
  731.       int factor;
  732.  
  733.         switch(size)
  734.         {
  735.           case P50:     factor = 50;
  736.                   break;
  737.  
  738.           case P75:     factor = 75;
  739.                 break;
  740.  
  741.       case PACTUAL: factor = 100;
  742.                 break;
  743.  
  744.           case P200:    factor = 200;
  745.                         break;
  746.         }
  747.         return(factor);
  748. }
  749.  
  750.  
  751.  
  752. /**************************************************************************/
  753. /* Function: scrn2mu()                              */
  754. /* Description: Converts screen coordinates to mu (PADJCNT specific)      */
  755. /**************************************************************************/
  756. scrn2mu(ox,oy,nx,ny,flag,flag2)
  757. int ox,oy;                    /* Old x,y vertice      */
  758. int *nx,*ny;                    /* New adjusted vertice   */
  759. int flag;                    /* scale direction flag   */
  760. int flag2;                    /* 0 = first page      */
  761.                         /* 2 = 2nd page          */
  762. {
  763.          int tmpx;
  764.          int tmpy;
  765.      int hwidth;
  766.      
  767.  
  768.          tmpx    = ox;                /* save for later...      */
  769.          tmpy    = oy;
  770.      zdevice = SCREEN;            /* Device destination     */
  771.  
  772.          if(!flag)
  773.          {
  774.          tmpx -= dpwork.g_x;        /* adjust for work offset */
  775.          tmpy -= dpwork.g_y;        /* of the window...       */
  776.          }
  777.  
  778.  
  779.          if((view_size == PSIZE) ||        /* Want Size to Fit       */
  780.             (view_size == PADJCNT))
  781.          {
  782.         hwidth = ((view_size == PADJCNT) ? (hpage_size * 2) : (hpage_size));
  783.         *nx = scale_iv(tmpx,hwidth,pagew);  
  784.         *ny = scale_iv(tmpy,vpage_size,pageh);
  785.  
  786.         if((flag2) && (view_size == PADJCNT) && (!flag) )
  787.         {
  788.         alt_offset = TRUE;
  789.         *nx -= hpage_size;
  790.         }
  791.         else
  792.         alt_offset = FALSE;
  793.                             
  794.          }
  795.          else                    /* otherwise all others   */
  796.          {
  797.             scale_xy(&tmpx,&tmpy,1);
  798.             *nx = hpixtomu(tmpx);
  799.         *ny = vpixtomu(tmpy);
  800.  
  801.             if(!flag)                /* adjust for the scrolled*/
  802.         {                    /* offset off of the      */
  803.                 *nx += page_area.g_x;        /* window          */
  804.                 *ny += page_area.g_y;        /* be adjusted...         */
  805.             }                        
  806.          }
  807.  
  808. }
  809.  
  810.  
  811.  
  812.  
  813.  
  814. /**************************************************************************/
  815. /* Function: do_trans_scale()                          */
  816. /* Description: Handles typed in coordinates for translation and scaling  */
  817. /**************************************************************************/
  818. do_trans_scale(oldx,oldy,oldwidth,oldheight,newx,newy,newwidth,newheight,type)
  819. int oldx,oldy,oldwidth,oldheight;
  820. int newx,newy,newwidth,newheight;
  821. int type;
  822. {
  823.          int opcode;
  824.     int fflag;
  825.     int fx,fy;
  826.         register int i;
  827.     int toggle;
  828.     int odeltax,ndeltax;
  829.     int odeltay,ndeltay;
  830.         int tempx,tempy;
  831.         int oldrect[4];
  832.  
  833.         oldrect[0] = oldx;
  834.      oldrect[1] = oldy;
  835.     oldrect[2] = oldx + oldwidth - 1;
  836.     oldrect[3] = oldy + oldheight - 1;
  837.  
  838.     if((oldx != newx) || (oldy != newy) || (oldwidth != newwidth)
  839.        || (oldheight != newheight))
  840.     {
  841.        if(snap_to_grids)
  842.        {
  843.         tempx = newx + newwidth;
  844.         tempy = newy + newheight;
  845.         snap_mu(&newx,&newy);
  846.         snap_mu(&tempx,&tempy);
  847.         newwidth  = tempx - newx;
  848.         newheight = tempy - newy;
  849.            }
  850.  
  851.        fx = (  (  (newx - oldx) < 0) ? (-1) : (1));
  852.        fy = (  (  (newy - oldy) < 0) ? (-1) : (1));
  853.  
  854.        deltax = abs(newx - oldx);
  855.        deltay = abs(newy - oldy);
  856.     
  857.        deltax *= fx;
  858.        deltay *= fy;
  859.        
  860.        opcode = get_fprimitive(region_ptr,&count,&wmode);
  861.        fflag = TRUE;
  862.        while(opcode != -1)
  863.        {
  864.         switch(opcode)
  865.         {
  866.             case 3:
  867.             case 4:
  868.             case 0: toggle = TRUE;        /* translate */
  869.                     for(i=0;i<(count*2);i++)
  870.                 {
  871.                    ptsarray[i] += ((toggle) ? (deltax):(deltay));
  872.                    toggle ^= TRUE;
  873.                 }
  874.  
  875.                 i = 0;            /* and scale */
  876.                 while(i<count*2)
  877.                 {
  878.                 odeltax = ptsarray[i] - newx;
  879.                 ndeltax = scale_iv(odeltax,newwidth,oldwidth);
  880.                 ptsarray[i++] = newx + ndeltax;
  881.  
  882.                 odeltay = ptsarray[i] - newy;
  883.                 ndeltay = scale_iv(odeltay,newheight,oldheight);
  884.                 ptsarray[i++] = newy + ndeltay;
  885.                 }
  886.  
  887.                 break;
  888.  
  889.             case 1: ptsarray[0] += deltax;    /* translate */
  890.                 ptsarray[1] += deltay;
  891.                             /* and scale */
  892.                 case12_scale(newx,newy,oldwidth,oldheight,
  893.                     newx,newy,newwidth,newheight,1);
  894.                 break;
  895.  
  896.             case 2: ptsarray[0] += deltax;    /* translate */
  897.                 ptsarray[2] += deltax;
  898.                 ptsarray[1] += deltay;
  899.                 ptsarray[3] += deltay;
  900.                             /* and scale */
  901.                 case12_scale(newx,newy,oldwidth,oldheight,
  902.                     newx,newy,newwidth,newheight,2);
  903.                 break;
  904.        
  905.         }    /* end of switch(opcode) */
  906.         update_primitive(opcode,count,wmode,fflag);
  907.         fflag = FALSE;
  908.         opcode = get_nprimitive(&count,&wmode);
  909.        }        /* end of while         */
  910.  
  911.        if(!type)        /* text only */
  912.        {        
  913.         page_redraw(region_ptr);
  914.        }
  915.        else
  916.         update_repel(1,oldrect);
  917.        if(view_size != PADJCNT && !deferhj && gl_region_ptr)
  918.         redraw_area(region_ptr,oldrect,1);
  919.     }
  920.     graf_mouse(0,&dummy);
  921. }
  922.  
  923.  
  924.  
  925.  
  926. /**************************************************************************/
  927. /* Function: case12_scale()                          */
  928. /* Description: Scale for opcodes 1 and 2 for typed in vertices          */
  929. /**************************************************************************/
  930. case12_scale(oldx,oldy,oldw,oldh,newx,newy,neww,newh,flag)
  931. int oldx,oldy,oldw,oldh;
  932. int newx,newy,neww,newh;
  933. int flag;
  934. {
  935.      int odeltax,odeltay;
  936.      int ndeltax,ndeltay;
  937.  
  938.      odeltax = ptsarray[0] - oldx;
  939.      ndeltax = scale_iv(odeltax,neww,oldw);
  940.      ptsarray[0] = newx + ndeltax;
  941.  
  942.      odeltay = ptsarray[1] - oldy;
  943.      ndeltay = scale_iv(odeltay,newh,oldh);
  944.      ptsarray[1] = newy + ndeltay;
  945.  
  946.      if(flag == 1)
  947.      {
  948.          odeltax = ptsarray[2];
  949.          ndeltax = scale_iv(odeltax,neww,oldw);
  950.          ptsarray[2] = ndeltax;
  951.  
  952.          odeltay = ptsarray[3];
  953.          ndeltay = scale_iv(odeltay,newh,oldh);
  954.          ptsarray[3] = ndeltay;
  955.      }
  956.      else
  957.      {
  958.          odeltax = ptsarray[2] - oldx;
  959.          ndeltax = scale_iv(odeltax,neww,oldw);
  960.          ptsarray[2] = newx + ndeltax;
  961.  
  962.          odeltay = ptsarray[3] - oldy;
  963.          ndeltay = scale_iv(odeltay,newh,oldh);
  964.          ptsarray[3] = newy + ndeltay;
  965.      }
  966. }
  967.  
  968.  
  969.  
  970.  
  971. /**************************************************************************/
  972. /* Function: scale_prim_coord()                              */
  973. /* Description: Scales primitive coordinates                  */
  974. /**************************************************************************/
  975. scale_prim_coord(opcode,oldx,oldy,oldwidth,oldheight,newx,newy,
  976.          newwidth,newheight,type,count,wmode)
  977. int opcode;
  978. int oldx,oldy,oldwidth,oldheight;
  979. int newx,newy,newwidth,newheight;
  980. int type;
  981. int count;
  982. int wmode; 
  983. {
  984.     int fx,fy;
  985.         register int i;
  986.     int toggle;
  987.     int odeltax,ndeltax;
  988.     int odeltay,ndeltay;
  989.         int tempx,tempy;
  990.  
  991.         int oldrect[4];
  992.  
  993.         oldrect[0] = oldx;
  994.      oldrect[1] = oldy;
  995.     oldrect[2] = oldx + oldwidth - 1;
  996.     oldrect[3] = oldy + oldheight - 1;
  997.  
  998.     if((oldx != newx) || (oldy != newy) || (oldwidth != newwidth)
  999.        || (oldheight != newheight))
  1000.     {
  1001.        if(snap_to_grids)
  1002.        {
  1003.         tempx = newx + newwidth;
  1004.         tempy = newy + newheight;
  1005.         snap_mu(&newx,&newy);
  1006.         snap_mu(&tempx,&tempy);
  1007.         newwidth  = tempx - newx;
  1008.         newheight = tempy - newy;
  1009.            }
  1010.  
  1011.        fx = (  (  (newx - oldx) < 0) ? (-1) : (1));
  1012.        fy = (  (  (newy - oldy) < 0) ? (-1) : (1));
  1013.  
  1014.        deltax = abs(newx - oldx);
  1015.        deltay = abs(newy - oldy);
  1016.     
  1017.        deltax *= fx;
  1018.        deltay *= fy;
  1019.  
  1020.         switch(opcode)
  1021.         {
  1022.             case 3:
  1023.             case 4:
  1024.             case 0: toggle = TRUE;        /* translate */
  1025.                     for(i=0;i<(count*2);i++)
  1026.                 {
  1027.                    ptsarray[i] += ((toggle) ? (deltax):(deltay));
  1028.                    toggle ^= TRUE;
  1029.                 }
  1030.  
  1031.                 i = 0;            /* and scale */
  1032.                 while(i<count*2)
  1033.                 {
  1034.                 odeltax = ptsarray[i] - newx;
  1035.                 ndeltax = scale_iv(odeltax,newwidth,oldwidth);
  1036.                 ptsarray[i++] = newx + ndeltax;
  1037.  
  1038.                 odeltay = ptsarray[i] - newy;
  1039.                 ndeltay = scale_iv(odeltay,newheight,oldheight);
  1040.                 ptsarray[i++] = newy + ndeltay;
  1041.                 }
  1042.  
  1043.                 break;
  1044.  
  1045.             case 1: ptsarray[0] += deltax;    /* translate */
  1046.                 ptsarray[1] += deltay;
  1047.                             /* and scale */
  1048.                 case12_scale(newx,newy,oldwidth,oldheight,
  1049.                     newx,newy,newwidth,newheight,1);
  1050.                 break;
  1051.  
  1052.             case 2: ptsarray[0] += deltax;    /* translate */
  1053.                 ptsarray[2] += deltax;
  1054.                 ptsarray[1] += deltay;
  1055.                 ptsarray[3] += deltay;
  1056.                             /* and scale */
  1057.                 case12_scale(newx,newy,oldwidth,oldheight,
  1058.                     newx,newy,newwidth,newheight,2);
  1059.                 break;
  1060.        
  1061.         }    /* end of switch(opcode) */
  1062.         update_primitive(opcode,count,wmode,0);
  1063.         recalc_region();
  1064.  
  1065.        if(!type)        /* text only */
  1066.        {
  1067.         page_redraw(region_ptr);
  1068.        }
  1069.        else
  1070.         update_repel(1,oldrect);
  1071.        if(view_size != PADJCNT && !deferhj && gl_region_ptr)
  1072.         redraw_area(region_ptr,oldrect,1);
  1073.     }
  1074.     graf_mouse(0,&dummy);
  1075. }
  1076.  
  1077.  
  1078.  
  1079.  
  1080. /**************************************************************************/
  1081. /* Function: mutopt()                              */
  1082. /* Description:                               */
  1083. /**************************************************************************/
  1084. mutopt(munits)
  1085. int munits;
  1086. {
  1087.    return(munits / 16);
  1088. }
  1089.